package cn.tworice.admin.service.impl;

import cn.tworice.admin.dao.NoticeDao;
import cn.tworice.admin.service.NoticeService;
import cn.tworice.common.entity.Notice;
import cn.tworice.common.entity.dto.NoticeDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeDao noticeDao;

    @Override
    public List<NoticeDto> getNoticeList(Integer page,Integer pageSize,Notice entity) {
        return noticeDao.queryNoticeList(page*pageSize,pageSize,entity);
    }

    /**
     * 添加通知
     * @author 二饭
     * @email 1786705138@qq.com
     */
    @Override
    public int addNotice(Notice notice) {
        if(notice.getId().isEmpty()){
            notice.setId(UUID.randomUUID().toString().replaceAll("-",""));
            notice.setDate(System.currentTimeMillis());
            return noticeDao.insertNotice(notice);
        }else {
            notice.setDate(System.currentTimeMillis());
            return noticeDao.updateNotice(notice);
        }
    }

    /**
     * 通过id删除
     * @author 二饭
     * @email 1786705138@qq.com
     */
    @Override
    public int rmNoticeById(String[] ids) {
        return noticeDao.delNoticeById(ids);
    }

    /**
     * 通过通知ID设置置顶状态
     * @author 二饭
     * @email 1786705138@qq.com
     */
    @Override
    public int setStatus(String id, Integer top) {
        return noticeDao.updateTopById(id,top);
    }

    @Override
    public List<NoticeDto> getTopNotice() {
        return noticeDao.queryTopNotice();
    }

    @Override
    public int getTotal(Notice entity) {
        return noticeDao.queryTotal(entity);
    }
}
